﻿#ifndef TOOLS_H
#define TOOLS_H

#include <QObject>
#include <QFile>
#include <QApplication>
#include <QColor>
#include <QPalette>
#include <QSettings>
#include <QInputDialog>
#include <QDebug>
#include <QMessageBox>
#include <QDate>
#include <QPushButton>

static QSettings MySettings("Ezcoding", "storemsclient");
static bool DEBUG = true;
class Tools : public QObject
{
    Q_OBJECT

public:
    explicit Tools(QObject *parent = nullptr);

    enum PasswordType{
        LoginPassword,
        OperatePassword
    };
    Q_ENUM(PasswordType)

    static void showRepeatProductMsg(){
        QMessageBox::warning(nullptr, "警告", "存在重复商品记录，已自动剔除！");
    }

    static QDate getBaseDate(){
        return QDate::fromString("2019-07-01", "yyyy-MM-dd");
    }

    static void setStyle(const QString &qssFile){
        QFile qss(qssFile);
        qss.open(QFile::ReadOnly);
        qApp->setStyleSheet(qss.readAll());
        qss.close();
    }

    static void setButtonState(QPushButton *button, bool state){
        if(button != nullptr){
            button->setEnabled(state);
        }
    }

    static void cout(QString text){
        if(DEBUG){
            qDebug()<<text.toUtf8().data();
        }
    }

    static QString toJsonStr(QString text){
        if(text.isEmpty()){
            return "\"\"";
        }

        return QString("\"%1\"").arg(text);
    }

    static void saveValue(QString prefix, QString key, QVariant value){
        MySettings.setValue(QString("%1/%2").arg(prefix).arg(key), value);
    }

    static QVariant loadValue(QString prefix, QString key){
        return MySettings.value(QString("%1/%2").arg(prefix).arg(key));
    }
signals:

public slots:

private:

};

#endif // TOOLS_H
